package revenge.jack_cristo.shiyuanbaoyou.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.text.DecimalFormat;
import java.util.List;

import revenge.jack_cristo.shiyuanbaoyou.R;
import revenge.jack_cristo.shiyuanbaoyou.bean.Shouye_listbean;


/**
 * Created by Jack-Cristo on 2016/11/12.
 */

public class Adapter_Shouye extends BaseAdapter {
    private Context context;
    private List<Shouye_listbean.RowsBean> listprodust;
    private LayoutInflater inflater;
    private static int d;

    public Adapter_Shouye(Context context, List<Shouye_listbean.RowsBean> listprodust) {
        this.context = context;
        this.listprodust = listprodust;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return listprodust.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Viewholder viewholder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.shouyelist_item_layout, null);
            viewholder = new Viewholder(view);
            view.setTag(viewholder);
        } else {
            viewholder = (Viewholder) view.getTag();
        }
        DecimalFormat df = new DecimalFormat("###.00");
        viewholder.titlt_item.setText(listprodust.get(i).getName());
        Glide.with(context).load(listprodust.get(i).getProductImg1()).into(viewholder.iv_item);
        viewholder.price.setText("￥" + df.format(listprodust.get(i).getNewPrice()) + "");
        viewholder.oldprice.setText(df.format(listprodust.get(i).getOldPrice()) + "");
        viewholder.oldprice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        viewholder.count.setText(df.format(listprodust.get(i).getDiscount()) + "折");
        Log.d("qqq", "￥" + df.format(listprodust.get(i).getNewPrice()) + "");
        Log.d("qqq", "已售" + listprodust.get(i).getSaleTotal() + "件");

        viewholder.salecount.setText("已售" + listprodust.get(i).getSaleTotal() + "件");//
        //////Log.d("qqq", "￥" + df.format(listprodust.get(i).getNewPrice()) + "");
        if (listprodust.get(i).getIsBaoYou() == 1) {
            viewholder.baoyou.setText("包邮");
        } else {
            viewholder.baoyou.setText("不包邮");
        }


        return view;
    }

    class Viewholder {
        private ImageView iv_item;
        private TextView titlt_item, price, count, salecount, baoyou, oldprice;

        public Viewholder(View view) {
            iv_item = (ImageView) view.findViewById(R.id.item_imag);
            titlt_item = (TextView) view.findViewById(R.id.title_item);
            price = (TextView) view.findViewById(R.id.pricr_item);
            count = (TextView) view.findViewById(R.id.count_item);
            salecount = (TextView) view.findViewById(R.id.salecount_item);
            baoyou = (TextView) view.findViewById(R.id.baoyou_item);
            oldprice = (TextView) view.findViewById(R.id.oldpricr_item);
        }

    }
}
